
//
//  SampuxAddEquipmentFaithView.m
//  Sampux
//
//  Created by rzm on 16/7/11.
//  Copyright © 2016年 rzm. All rights reserved.
//

#import "SampuxAddEquipmentFaithView.h"

@interface SampuxAddEquipmentFaithView ()

@end

@implementation SampuxAddEquipmentFaithView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupSubView];
    }
    return self;
}

- (void)setupSubView
{
    
    CGFloat font = 8.;
    if (IS_IPHONE_4_OR_LESS) {
        font = 12.;
    }else if (IS_IPHONE_5_OR_LESS)
    {
        font = 13.;
    }else if (IS_IPHONE_6)
    {
        font = 14.;
    }else
    {
        font = 15.;
    }

    UIScrollView *scrollview =  [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    [self addSubview:scrollview];
    
    
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(self.width/2 - 40, Sampux6HScale(10) + 64, 80, Sampux6HScale(30))];
    lab.text = @"添加失败!";
    [scrollview addSubview:lab];
    lab.textColor = THWhiteAlplaColor(0.6);
    lab.textAlignment = NSTextAlignmentCenter;

    UIButton *imgBtn = [UIButton createButton];
    [scrollview addSubview:imgBtn];
    imgBtn.frame = CGRectMake(self.width/2 - 130/4, lab.bottom, 130/2, 130/2);
    [imgBtn setImage:imageNamed(@"fail") forState:UIControlStateNormal];
    imgBtn.userInteractionEnabled = NO;
    
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(self.width * 0.1, imgBtn.bottom + Sampux6HScale(40), self.width * 0.8, Sampux6HScale(200))];
    [scrollview addSubview:backView];
    backView.backgroundColor = THWhiteAlplaColor(0.12);
    [backView setCorner:5];
    
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, backView.width, backView.height * 0.18)];
    [backView addSubview:titleLab];
    titleLab.text = @"可能的原因";
    titleLab.backgroundColor = THWhiteAlplaColor(0.24);
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.textColor = THWhiteAlplaColor(0.6);
    titleLab.font = THFont(font + 2);
    
    UILabel *lab1 = [[UILabel alloc]initWithFrame:CGRectMake(Sampux6WScale(SampuxMargin), titleLab.bottom + SampuxMargin, backView.width - Sampux6WScale(SampuxMargin)*2, backView.height * 0.1)];
    [backView addSubview:lab1];
    lab1.text = @"1.设备ID输入错误";
    lab1.textColor = THWhiteAlplaColor(0.6);
    lab1.font = THFont(font);

    UILabel *lab2 = [[UILabel alloc]initWithFrame:CGRectMake(Sampux6WScale(SampuxMargin), lab1.bottom + Sampux6HScale(SampuxMargin), backView.width - Sampux6WScale(SampuxMargin)*2, backView.height * 0.1)];
    [backView addSubview:lab2];
    lab2.text = @"2.设备无处于配置状态";
    lab2.textColor = THWhiteAlplaColor(0.6);
    lab2.font = THFont(font);

    UILabel *lab3 = [[UILabel alloc]initWithFrame:CGRectMake(Sampux6WScale(SampuxMargin), lab2.bottom + Sampux6HScale(SampuxMargin), backView.width - Sampux6WScale(SampuxMargin)*2, backView.height * 0.1)];
    [backView addSubview:lab3];
    lab3.text = @"3.网络不稳定或网速太慢";
    lab3.textColor = THWhiteAlplaColor(0.6);
    lab3.font = THFont(font);

    UILabel *lab4 = [[UILabel alloc]initWithFrame:CGRectMake(Sampux6WScale(SampuxMargin), lab3.bottom + Sampux6HScale(SampuxMargin), backView.width - Sampux6WScale(SampuxMargin)*2, backView.height * 0.1)];
    [backView addSubview:lab4];
    lab4.text = @"4.路由器设置不当或WiFi密码不正确";
    lab4.textColor = THWhiteAlplaColor(0.6);
    lab4.font = THFont(font);

    
    UILabel *lab5 = [[UILabel alloc]initWithFrame:CGRectMake(Sampux6WScale(SampuxMargin), lab4.bottom + Sampux6HScale(SampuxMargin), backView.width - Sampux6WScale(SampuxMargin)*2, backView.height * 0.1)];
    [backView addSubview:lab5];
    lab5.text = @"5.设备应在路由器信号覆盖范围内";
    lab5.textColor = THWhiteAlplaColor(0.6);
    lab5.font = THFont(font);
    
    
    UILabel *lab6 = [[UILabel alloc]initWithFrame:CGRectMake(Sampux6WScale(SampuxMargin), lab5.bottom + Sampux6HScale(SampuxMargin), backView.width - Sampux6WScale(SampuxMargin)*2, backView.height * 0.1)];
    [backView addSubview:lab6];
    lab6.text = @"6.连接5G频段的WiFi，请关闭5G频段";
    lab6.textColor = THWhiteAlplaColor(0.6);
    lab6.font = THFont(font);
    
    UILabel *lab7 = [[UILabel alloc]init];
    lab7.numberOfLines = 0;
//    lab7.lineBreakMode = NSLineBreakByWordWrapping;
    lab7.origin = CGPointMake(Sampux6WScale(SampuxMargin), lab6.bottom + Sampux6HScale(SampuxMargin)) ;
    lab7.font = THFont(font);
    lab7.text = @"7.WiFi信号太多干扰大，解决方法请见帮助中心";
//    CGSize size = [lab7.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:THFont(font),NSFontAttributeName, nil]];
    CGSize size = [lab7 sizeThatFits:CGSizeMake(backView.width - Sampux6WScale(SampuxMargin)*2, MAXFLOAT)];
    lab7.size = CGSizeMake(backView.width - Sampux6WScale(SampuxMargin)*2, size.height);
    [backView addSubview:lab7];
    lab7.textColor = THWhiteAlplaColor(0.6);
    backView.height = lab7.bottom + Sampux6HScale(15);

    UIButton *btn = [UIButton createButtonWithTitle:@"重试" buttonType:UIButtonTypeCustom frame:CGRectMake(self.width/2 - Sampux6WScale(345/2)/2, backView.bottom + SampuxMargin *2, Sampux6WScale(345/2),Sampux6HScale(SampuxCustomH)) titleFont:[UIFont systemFontOfSize:16.0] titleColor:THDeFaultBlueColor backColor:THSystemClearColor];
    [scrollview addSubview:btn];
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = THWhiteAlplaColor(0.6).CGColor;
    [btn setCorner:btn.height/2];
    [btn addTarget:self action:@selector(retryBtnClick) forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font = THFont(font + 1);

    UIButton *helpBtn = [UIButton createButtonWithTitle:@"帮助中心" buttonType:UIButtonTypeCustom frame:CGRectMake(self.width - 80 - 15, btn.bottom + Sampux6HScale(10), 80,Sampux6HScale(SampuxCustomH)) titleFont:[UIFont systemFontOfSize:16.0] titleColor:THDeFaultBlueColor backColor:THSystemClearColor];
    [scrollview addSubview:helpBtn];
    [helpBtn addTarget:self action:@selector(helpBtnClick) forControlEvents:UIControlEventTouchUpInside];
    helpBtn.titleLabel.font = THFont(font + 1);
    
    scrollview.contentSize = CGSizeMake(scrollview.frame.size.width, helpBtn.bottom + Sampux6HScale(20));
}

- (void)helpBtnClick
{
    if (self.helpBlock) {
        self.helpBlock();
    }
}

- (void)retryBtnClick
{
    if (self.retryBlock) {
        self.retryBlock();
    }
}

@end
